package com.voltmao.energy.Util;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Msg {

	public static void sendToFront(HttpServletRequest req,HttpServletResponse res,HashMap<String,Object> msg){
		String jsonlist;
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(Include.NON_NULL);
		try {
			jsonlist = mapper.writeValueAsString(msg);
			res.setCharacterEncoding("UTF-8"); //设置编码格式
			res.setContentType("text/json");   //设置数据格式
			PrintWriter out = res.getWriter(); //获取写入对象
			out.print(jsonlist); //将json数据写入流中
			out.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
